<template>
  <div class="login">
    <div class="login_wrapper">
      <div class="login-wrapper-bg"/>
      <div class="login-content">
        <div class="login-form">
          <div class="login-title">
            <div class="login-title-text">演示demo前端</div>
            <div class="login-title-text">数据支撑平台</div>
          </div>
          <div class="login-account-form">
            <el-form ref="loginForm" :model="loginForm" :rules="loginRules">
              <el-form-item class="login-form__line" prop="username">
                <el-input v-model="loginForm.username" placeholder="请输入登录系统的账号" @keyup.enter="handleLogin"></el-input>
              </el-form-item>
              <el-form-item class="login-form__line" prop="password">
                <el-input v-model="loginForm.password" type="password" placeholder="请输入登录系统的密码"
                          @keyup.enter="handleLogin"></el-input>
              </el-form-item>
              <el-form-item class="login-form__line">
                <el-input
                  v-model="loginForm.code"
                  auto-complete="off"
                  placeholder="验证码随便填不校验"
                  @keyup.enter.native="handleLogin"
                />
              </el-form-item>
              <div class="login-btn" @click="handleLogin">登 录</div>
              <div class="remember-line" :class="{'active': loginForm.rememberMe}" @click="handleRemember">
                <div class="remember-box">
                  <!-- <svg-icon icon-class="check" class-name="remember-box-checked"/> -->
                </div>
                <span class="remember-text">记住密码</span>
              </div>
            </el-form>
          </div>
        </div>
      </div>

    </div>
    <div class="copyright">
      <!-- <div>Copyright © 2021-2022 安徽省交控集团</div> -->
      <div class="mt-1" style="font-size: 13px; color:white">-- 技术支持 @ 糊里糊涂老迷糊 --</div>
    </div>
  </div>
</template>
<script>
import userInfo from '@/utils/user.js'
import Cookies from "js-cookie";
export default {
  name: "Login",
  data() {
    return {
      show: true,
      codeUrl: "",
      loginForm: {
        username: "",
        password: "",
        rememberMe: false,
        code: "",
        uuid: "",
      },
      loginRules: {
        username: [{ required: true, trigger: "blur", message: "请输入您的账号" },
        { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }],
        password: [{ required: true, trigger: "blur", message: "请输入您的密码" },
        { min: 5, message: '长度至少有5位字符', trigger: 'blur' }],
        code: [{ required: true, trigger: "change", message: "请输入验证码" }],
      },
      loading: false,
      // 验证码开关
      captchaOnOff: true,
      // 注册开关
      register: false,
      redirect: undefined,
    };
  },
  watch: {
    $route: {
      handler: function (route) {
      },
      immediate: true,
    },
  },
  created() {
    // this.getCookie();
    // this.getCode();
  },
  methods: {
    handleRemember() {
      this.loginForm.rememberMe = !this.loginForm.rememberMe;
    },
    handleLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          const boll = userInfo.some(item=>{
            if(item.userName == this.loginForm.username && item.passWard == this.loginForm.password){
              localStorage.setItem('userInfo',JSON.stringify(item))
            }
            return item.userName == this.loginForm.username && item.passWard == this.loginForm.password
          })
          if(boll){
            localStorage.setItem('tagView', JSON.stringify([]))
            Cookies.set('token', 'Admin-Token')
            this.$router.push('/dashboard')
          }else{
            this.$message.error('账号或者密码错误，请重新输入')
          }
          
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../../assets/style/login.scss";
</style>
